package cn.tedu.charging.device.controller;


import cn.tedu.charging.commom.pojo.JsonResult;
import cn.tedu.charging.commom.pojo.param.GunStatusUpdateParam;
import cn.tedu.charging.commom.pojo.vo.StationInfoVO;
import cn.tedu.charging.device.service.DeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备接口
 */
@Slf4j
@RequestMapping("/device")
@RestController
@Api(tags = "设备接口")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    /**
     * 附近的充电站
     * @param gunId
     * @return
     */
    @ApiOperation("附近的充电站")
    @GetMapping("/station/near")
    public JsonResult getNearStation(Double longitude, Double latitude, Double radius) {
        log.debug("获取附近的充电站经度:{},维度:{},距离:{}",longitude,latitude,radius);
        List<StationInfoVO> stationInfoVOs = deviceService.getNearStation(longitude,latitude,radius);
        return JsonResult.ok(stationInfoVOs);
    }



    /**
     * 获取场站信息
     * @param gunId
     * @return
     */
    @ApiOperation("获取场站信息")
    @GetMapping("/station/info/{gunId}")
    public JsonResult getStationInfo(@PathVariable("gunId") Integer gunId) {
        log.debug("获取场站信息入参:{}",gunId);
        log.debug("获取场站信息调用service入参:{}",gunId);
        StationInfoVO stationInfoVO = deviceService.getStationInfo(gunId);
        log.debug("获取场站信息调用service入参:{},出参:{}",gunId,stationInfoVO);
        JsonResult jsonResult = JsonResult.ok(stationInfoVO, "获取场站信息成功");
        log.debug("获取场站入参:{},出参:{}",gunId,jsonResult);
        return jsonResult;
    }


    /**
     * 更新枪状态
     * @param gunStatusUpdateParam
     * /updateStationGunStatus
     *
     * 资源/动作
     * /device/station/gun/status/update
     * /device/station/gun/status/del
     * /device/station/gun/status/add
     *
     * 动作/资源
     * /device/update/station/gun/status
     * /device/del/station/gun
     * /device/update/station/pile/status
     *
     * @return
     */
    @ApiOperation("更新枪状态")
    @PostMapping("/station/gun/status/update")
    public JsonResult updateGunStatus(@RequestBody GunStatusUpdateParam gunStatusUpdateParam) {
        log.debug("更新枪状态入参:{}",gunStatusUpdateParam);
        log.debug("更新枪状态调用service入参:{}",gunStatusUpdateParam);
        Boolean success = deviceService.updateGunStatus(gunStatusUpdateParam);
        log.debug("更新枪状态调用service入参:{},出参:{}",gunStatusUpdateParam,success);
        JsonResult jsonResult = JsonResult.ok(success, "更新枪状态成功");
        log.debug("更新枪状态入参:{},出参:{}",gunStatusUpdateParam,jsonResult);
        return jsonResult;
    }

}
